package com.prs.crm.service.fs.impl;

import java.io.File;
import java.util.Collection;

import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.fs.OutlayApplyDao;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.flow.WorkFlowProcessNode;
import com.prs.crm.domain.fs.ApplyDetail;
import com.prs.crm.domain.fs.OutlayApply;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.fs.ApplyDetailService;
import com.prs.crm.service.fs.OutlayApplyService;
import com.prs.crm.service.impl.FlowServiceImpl;

public class OutlayApplyServiceImpl extends FlowServiceImpl<OutlayApply,OutlayApplyDao> implements OutlayApplyService{
	private ApplyDetailService applyDetailService;
	
	@Override
	public void submitOutlayApply(Collection<ApplyDetail> applyDetails,OutlayApply outlayApply, File file,
			String fileName) {
		// TODO Auto-generated method stub
		Attachment attach = FileUtil.getInstance().createAttach(file, fileName);
		if(attach != null) {
			outlayApply.setAttach(attach);
		}
		this.getDao().save(outlayApply);
		
		for(ApplyDetail detail : applyDetails) {
			ApplyDetail applyDetail = new ApplyDetail();
			applyDetail.setApply(outlayApply);
			applyDetail.setItem(detail.getItem());
			applyDetail.setMoney(detail.getMoney());
			applyDetail.setSummary(detail.getSummary());
			this.getApplyDetailService().save(applyDetail);
		}
	}
	
	
	@Override
	public boolean valideSubmit(OutlayApply apply)
	{
		return true;
	}
	
	public void setApplyDetailService(ApplyDetailService applyDetailService) {
		this.applyDetailService = applyDetailService;
	}

	public ApplyDetailService getApplyDetailService() {
		return applyDetailService;
	}


	@Override
	public Collection<WorkFlowProcessNode> getHistoryFlowNode(
			OutlayApply outlayApply) {
		// TODO Auto-generated method stub
		return this.getWorkflowProcessService().pageHistoryFlowNode(outlayApply);
	}


	@Override
	public Collection<OutlayApply> getExistAuditInfoByPerson(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getExistAuditInfoByPerson(person);
	}

}
